package org.brownflat.watergate.domain;

import org.hibernate.annotations.Cascade;

import javax.persistence.Access;
import javax.persistence.AccessType;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;
import javax.persistence.Table;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>&copy Rupert Jones 2012</p>
 *
 * @author rup
 */
@Entity
@Table(name="wgate_comment")
public class Comment extends BaseEntity {

    @ManyToOne
    @JoinColumn(name="user_id")
    private User user;

    private String comment;

    @ManyToOne
    @JoinColumn(name="parent_id")
    private Comment parent;

    @OneToMany(mappedBy="parent", orphanRemoval = true)
    @Access(value= AccessType.PROPERTY)
    @Cascade( { org.hibernate.annotations.CascadeType.ALL } )
    @OrderBy("id desc")
    private List<Comment> children = new ArrayList<Comment>();

    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }

    public String getComment() {
        return comment;
    }

    public void setComment(String comment) {
        this.comment = comment;
    }

    public Comment getParent() {
        return parent;
    }

    public void setParent(Comment parent) {
        this.parent = parent;
    }

    public List<Comment> getChildren() {
        return children;
    }

    public void setChildren(List<Comment> children) {
        this.children = children;
    }
}
